package br.brpv.silvestrin.conferencia.webservice;

import android.content.Context;
import android.content.SharedPreferences;



public class Webservice {
	// O caractere de quebra de linha da tabela retornada pelo settings_webservice
    public final static char ROW_BREAK_CHARACTER = (char) 30;
    // O caractere de quebra de coluna da tabela retornada pelo settings_webservice
    public final static char COLUMN_BREAK_CHARACTER = (char) 31;
    
	public enum Status {
        SUCCESS, FAIL
    }

	public static final String WEB_SERVICE_PREFERENCES = "webservicePreferences";
	public static final String SERVER_URL = "webserviceURL";
	public static final String SERVER_PASSWORD = "webservicePassword";
	public static final String SERVER_USER = "webserviceUser";	
	public static final String SERVER_NAME = "webserviceName";
	
	Context context;	
	
	public Webservice(Context context) {
		super();
		this.context = context;
	}

	public Status initializeServer(){
        SharedPreferences preferences = context.getSharedPreferences(Webservice.WEB_SERVICE_PREFERENCES, 0);
        String serverUrl = preferences.getString(Webservice.SERVER_URL,"");
        if(serverUrl.equalsIgnoreCase("")) return Status.FAIL;
        String serverUser = preferences.getString(Webservice.SERVER_USER, "");
        if(serverUser.equalsIgnoreCase("")) return Status.FAIL;
        String serverPass = preferences.getString(Webservice.SERVER_PASSWORD, "");
        if(serverPass.equalsIgnoreCase("")) return Status.FAIL;

        setParameters(serverUrl, serverUser, serverPass);
        return Status.SUCCESS;
    }
	
	public void setParameters(String url, String user, String password) {
        WebserviceManager.setURL(url);
        WebserviceManager.setUser(user);
        WebserviceManager.setPassword(password);
    }

}
